// run: $exec < input
// opt: 0
// flag: -g
#include <iostream>
#include <utility>
#include <algorithm>
#include <vector>
#include <map>

std::vector<int> a;
std::map<int, int> count;
std::map<int, std::pair<int, int>> range;
int n;

int main()
{
	std::ios::sync_with_stdio(false);
	std::cin >> n;
	a.resize(n);
	for (int i = 0; i < n; i++) {
		std::cin >> a[i];
		count[a[i]]++;
	}
	int sum = 0;
	for (auto i : count) {
		range[i.first].first = sum;
		sum += i.second;
		range[i.first].second = sum;
	}

	int tot = 0;
	for (int i = 0; i < n; i++)
		if (i < range[a[i]].first || i >= range[a[i]].second)
			tot++;
	if (tot > 2) std::cout << "NO\n";
	else std::cout << "YES\n";
}

